package com.fivestar.pmanager.core.util;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.log4j.Logger;

public class LoggerHelper
{

    public static void logError(Logger log, String controller, Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);

        strBuffer.append(">>> Exception occured. [KEY-" + controller
                + "].");

        log.error(strBuffer, ex);
    }
    
    public static void logError(Logger log,Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);
        strBuffer.append(">>> ");
        log.error(strBuffer, ex);
    }


    public static String logTicketNo(Logger log, Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);

        String ticketNo = String.valueOf(System.currentTimeMillis());

        strBuffer.append(">>> Exception occured. [TICKET-" + ticketNo + "],");

        log.error(strBuffer, ex);

        return ticketNo;
    }


    public static String logTicketNo(Logger log, String controller,
            Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);

        String ticketNo = String.valueOf(System.currentTimeMillis());

        strBuffer.append(">>> Exception occured. [TICKET-" + ticketNo + "], [KEY-"
                + controller + "].");

        log.error(strBuffer, ex);

        return ticketNo;
    }
    
    
    


    public static String getStackTrace(Exception ex)
    {
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        return sw.toString();
    }
    
    
    public static void logError(org.slf4j.Logger log, String controller, Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);

        strBuffer.append(">>> Exception occured. [KEY-" + controller
                + "].");

        log.error(strBuffer.toString(), ex);
    }
    
    public static void logError(org.slf4j.Logger log,Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);
        strBuffer.append(">>> ");
        log.error(strBuffer.toString(), ex);
    }


    public static String logTicketNo(org.slf4j.Logger log, Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);

        String ticketNo = String.valueOf(System.currentTimeMillis());

        strBuffer.append(">>> Exception occured. [TICKET-" + ticketNo + "],");

        log.error(strBuffer.toString(), ex);

        return ticketNo;
    }


    public static String logTicketNo(org.slf4j.Logger log, String controller,
            Exception ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);

        String ticketNo = String.valueOf(System.currentTimeMillis());

        strBuffer.append(">>> Exception occured. [TICKET-" + ticketNo + "], [KEY-"
                + controller + "].");

        log.error(strBuffer.toString(), ex);

        return ticketNo;
    }
    
    
    public static void logError(org.slf4j.Logger log,Throwable ex)
    {
        StringBuffer strBuffer = new StringBuffer(200);
        strBuffer.append(">>> ");
        log.error(strBuffer.toString(), ex);
    }
}
